fix(endpoint-cache): reduce bundle size #2400
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
mnemonist
is a pretty big (well, for web-bundles anyway) commonjs package, which is currently included IN FULL from the endpoint-cache package. This is less than ideal when using the sdk on the frontend side, since it adds about 270kb to the bundle (before minification).Since only the LRU-Cache is needed, changing the import to directly target the lru-cache module helps bundlers tree shake correctly, reducing the included code to about 15kb.
Testing
I ran compilation on the
endpoint-cache
package and executed the commonjs build vianode dist/cjs/EndpointCache.js
just to check if the import would throw. I tested the es build integrated in my webpack project to check the reduced bundle size.Also ran
yarn test:all
Additional context
Before:
After:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.